home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 55375 / 55375.xpi / chrome / chromeFiles / content / btUtilities.js < prev    next >
Text File  |  2009-11-15  |  40KB  |  1,026 lines

  1. /* This filech contains helper functions */
  2. /* It has to be included AFTER btClient.js */
  3.  
  4. BrandThunder.initialize = function(brandObject) {
  5.   var AMO = false;
  6.   var includeBing = false;
  7.   var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
  8.                            .getService(Components.interfaces.nsIPrefBranch);
  9.  
  10.   var btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  11.                                .getService(Components.interfaces.nsIPrefService)
  12.                                .getBranch("extensions.brandthunder.");
  13.  
  14.   if (!brandObject.utilities) {
  15.     brandObject.utilities = {};
  16.   }
  17.   function log(string) {
  18.     var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"]
  19.                                  .getService(Components.interfaces.nsIConsoleService);   
  20.     aConsoleService.logStringMessage(string);
  21.   }
  22.   /* This function uses the presence of a rebranding extension to indicate */
  23.   /* That this is a full build, not just the extension/theme */
  24.   function isFullBuild() {
  25.     return false;
  26.   }
  27.   function openLink(brandObject, event, url) {
  28.     if (typeof(url) == "undefined") {
  29.       url = brandObject.urls[event.target.id];
  30.     }
  31.     if (brandObject.redirect && !url.match("redirect.php") && !url.match("faq.php") && !url.match("firstrun.php")  && !url.match("getsatisfaction.com")) {
  32.       url = brandObject.redirect + "?url=" + url;
  33.     }
  34.     if (url.match("redirect.php")) {
  35.       url += "&client=" + brandObject.releaseIdentifier;
  36.       //var curLang = "en";
  37.       //try {
  38.       //  curLang = Components.classes["@mozilla.org/preferences-service;1"]
  39.       //                        .getService(Components.interfaces.nsIPrefService)
  40.       //                        .getBranch(null)
  41.       //                        .getCharPref("general.useragent.locale")
  42.       //                        .substr(0,2);
  43.       //}
  44.       //catch (e) {}
  45.       //if (curLang != "en") {
  46.       //  url += "&lang=" + curLang;
  47.       //}
  48.     }
  49.     
  50.     
  51.     
  52.   //  openUILink(url, event);
  53.     var tab = getBrowser().addTab(url);
  54.     getBrowser().selectedTab = tab;
  55.     return;
  56.   }
  57.   function restartApp() {
  58.     // Notify all windows that an application quit has been requested.
  59.     var os = Components.classes["@mozilla.org/observer-service;1"]
  60.                        .getService(Components.interfaces.nsIObserverService);
  61.     var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  62.                                .createInstance(Components.interfaces.nsISupportsPRBool);
  63.     os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
  64.   
  65.     // Something aborted the quit process.
  66.     if (cancelQuit.data)
  67.       return;
  68.     var nsIAppStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
  69.                                         .getService(Components.interfaces.nsIAppStartup);
  70.     nsIAppStartup.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);    
  71.   }
  72.   /* This function generates a release identifier of the form: */
  73.   /* 001-Brand# (to be assigned per brand as they come in) */
  74.   /* X = Type of release (x = xpi, e = exe, d = dmg, file extension) */
  75.   /* 001- Release Version (just incremented by 1 for each release for the brand) */
  76.   /* US - country (US, CA, etc) */
  77.   function getReleaseIdentifier(brandObject) {
  78.     var releaseIdentifier = brandObject.clientCode;
  79.     var rdfs = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  80.                          .getService(Components.interfaces.nsIRDFService);
  81.     var extensionDS= Components.classes["@mozilla.org/extensions/manager;1"]
  82.                                .getService(Components.interfaces.nsIExtensionManager).datasource;
  83.     var extension = rdfs.GetResource("urn:mozilla:item:" + brandObject.extensionID);
  84.  
  85.     var arc = rdfs.GetResource("http://www.mozilla.org/2004/em-rdf#updateURL");
  86.     var updateURL = extensionDS.GetTarget(extension, arc, true);    if (updateURL) {
  87.       releaseIdentifier += "X";
  88.     } else {
  89.       releaseIdentifier += "A";
  90.     }
  91.     releaseIdentifier += brandObject.clientVersion;
  92.     releaseIdentifier += brandObject.clientCountry;
  93.   
  94.     return releaseIdentifier;
  95.   }
  96.   function addToPermissionManager(domain) {
  97.     var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  98.                               .getService(Components.interfaces.nsIIOService);
  99.     var pm = Components.classes["@mozilla.org/permissionmanager;1"]
  100.                        .getService(Components.interfaces.nsIPermissionManager);
  101.  
  102.     var uri = ioService.newURI("http://" + domain, null, null);
  103.     pm.add(uri, "popup", 1);
  104.     pm.add(uri, "install", 1);
  105.   }
  106.  
  107.   function addAsk(brandObject, replace) {
  108.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  109.                               .getService(Components.interfaces.nsIBrowserSearchService);
  110.  
  111.     var oldPosition;
  112.     var oldEngine;
  113.  
  114.     if (replace) {
  115.       var visibleEngines = searchSvc.getVisibleEngines({});
  116.  
  117.       for (let i=0; i < visibleEngines.length; i++) {
  118.         if (visibleEngines[i].name == "Ask") {
  119.           oldPosition = i;
  120.           oldEngine = visibleEngines[i];
  121.           break;
  122.         }
  123.       }
  124.       if (oldEngine) {
  125.         searchSvc.removeEngine(oldEngine);
  126.       }
  127.     }
  128.  
  129.     searchSvc.addEngineWithDetails("Ask", "data:image/x-icon;base64,AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAQAEAAAAAAAAAAAAAAAEAAAAAAACbm5sAAADJAAAA1gAAANMAAADYAAAAyACcnJ0AAADLAAEBywDCwsAAjIy2AH9/gwBdXa4AAAC5AAAAygAwMOEAMjLgADMzvQAEBHwAaGipAAAAzwCtsLEAhYWgAAsLygDq6toAQkK3AGZnigA5O84ACAiuANjY3wAICIsAAADAAGVljgAEBIQAAADfAGNiegAREZAAwsLzAAcHkwAEBZ0Ag4jOAC0twAALC7QAqK7dAKSq1wBycqQABATQAPT04ACYm74ARkaOALO09wAmJnQAJSXJADw9fwAzNc4ALzDCAHp6pACdnZkApKevAL29sQD5+foAkpKcAOzs4AAMDMoAPj7iAKGinACvr6oAT0/wAAwNyQAAANIAlJTaAN/f0QCcnZ0AAADRAF5erQAAAJ8AAADDAAAAzAA1NrwAMTGfAAkJ1QAAAMQAWlqvAHJ31wDMzMAAFhbHAAAAiQBERNIA8fHmAAgI1gCys6oAu7v4AD09ngDDwfoABgbOAM7N9wCYmPUAKyuOABkZmgAyMsEAiYq8AHp68gDDw5sAAgLPALW2rwCdnZgAAAC9AAMD1wCenpgA9fX1AAAArQCCgrIA0dLYAK+vnwB3e9kA5ubSAOfn+AClp6cA3NzDAMHHygBQU9MABATCAG5z2gAcHMQAio/aAAAA2QD19fwAnaHIAIaGogDm5uoAk5N0AK+ytAAMDNUAAAAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////////////////////////////////////////////+DBgAAAAAASBX///////8GEzQ/Ll5VEUo9aXX///86e08hAg1qUUUiaymAOXf/NxQlglZvIzgzHksFeQxs/xcBEG1aWC1lc2YgCmEEUkE2BwFdaHAkQ3RGRxgqAmcWKwgFD1Q7Yn4xYzx2En0DGf9TBwFbLyZgCVwdQgtuBE7//3xEQD4nA1BZgTVXHwIw/////3pkHEkOTV8aTIR//////////yxyeBsycSj/////////////////////////////////////////////////AAD//wAA//8AAMAfAACABwAAAAEAAAABAAAAAAAAAAAAAAAAAACAAAAAwAAAAPABAAD8BwAA//8AAP//AAA=",
  130.                                    "", "Ask - BT", "GET",
  131.                                    "http://www.ask.com/web?q={searchTerms}&o=" + brandObject.askOriginCode + "&l=dis");
  132.  
  133.     var newEngine = searchSvc.getEngineByName("Ask");
  134.  
  135.     if (replace && oldPosition) {
  136.       searchSvc.moveEngine(newEngine, oldPosition);
  137.     }
  138.     return newEngine;
  139.   }
  140.   function addYahoo(brandObject, replace) {
  141.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  142.                               .getService(Components.interfaces.nsIBrowserSearchService);
  143.  
  144.     var oldPosition;
  145.     var oldEngine;
  146.  
  147.     if (replace) {
  148.       var visibleEngines = searchSvc.getVisibleEngines({});
  149.  
  150.       for (let i=0; i < visibleEngines.length; i++) {
  151.         if (visibleEngines[i].name == "Yahoo") {
  152.           oldPosition = i;
  153.           oldEngine = visibleEngines[i];
  154.           break;
  155.         }
  156.       }
  157.       if (oldEngine) {
  158.         searchSvc.removeEngine(oldEngine);
  159.       }
  160.     }
  161.  
  162.     searchSvc.addEngineWithDetails("Yahoo!", "data:image/x-icon;base64,R0lGODlhEAAQAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0NogQuyBDEnEd2kHkfFWUamEzmpZSfmaIHPHrRguUm/fT+UwAAOw==",
  163.                                    "", "Yahoo! - BT", "GET",
  164.                                    "http://search.yahoo.com/search?ei=utf-8&fr=chrff-brandt_off&p={searchTerms}&type=" + brandObject.releaseIdentifier);
  165.  
  166.     var newEngine = searchSvc.getEngineByName("Yahoo!");
  167.  
  168.     if (replace && oldPosition) {
  169.       searchSvc.moveEngine(newEngine, oldPosition);
  170.     }
  171.     return newEngine;
  172.   }
  173.   function addBing(brandObject, replace) {
  174.     if (!includeBing) {
  175.       return undefined;
  176.     }
  177.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  178.                               .getService(Components.interfaces.nsIBrowserSearchService);
  179.  
  180.     var oldPosition;
  181.     var oldEngine;
  182.  
  183.     if (replace) {
  184.       var visibleEngines = searchSvc.getVisibleEngines({});
  185.  
  186.       for (let i=0; i < visibleEngines.length; i++) {
  187.         if (visibleEngines[i].name == "Bing") {
  188.           oldPosition = i;
  189.           oldEngine = visibleEngines[i];
  190.           break;
  191.         }
  192.       }
  193.       if (oldEngine) {
  194.         searchSvc.removeEngine(oldEngine);
  195.       }
  196.     }
  197.  
  198.     searchSvc.addEngineWithDetails("Bing", "data:image/x-icon;base64," +
  199.                                    "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABmElEQVR4nK2TvS8DcRzGP3dV6Utw" +
  200.                                    "baNLm7hBY0A0BgaDW8/U3YDJVDHaXOIvEKOBRWJk0VENJN1Qg4R4iw4q5Wj6EnJ+hrtrcppIpL7j" +
  201.                                    "7+V5nu/zfb6SEIJOSiJ7IQC0VJjDrCr9FUDuiP4/ALp+HpyVmmLvvMppqYHZ+AJACcqkE0G0VIjp" +
  202.                                    "wbCnzZYHatQPwN3L56+MatSPMRNnbkKRPABu9QVlDD1OZrQHNdZtg1Y+yF/XMHLP3DsE85MKW7MJ" +
  203.                                    "yQMwlgiQz6ooIR+8XsBjzr5I6hAZwaxbaBt3nJWaABh63KvgdjVls97sQmHJq318DYYWMesWkZVL" +
  204.                                    "xxufdwquZG5325t31CghH9ODIQDMhoXsmuf2CkB8qh1AGbE/1S2OruutY8k4KAsjV2734OkYyif2" +
  205.                                    "q8gwJGcAyGw+sF+sArCsxZCEECzslMR2wQRgIOrH0PvJjPbaQA7rXvHdMwU3+pK7TOv5ijByz5gN" +
  206.                                    "y6O8Lyjz5gTKNW5Zi7Gq99s5+LmN+8WqyF/VOHVG5VY6ESCdDLQC1PKg03X+BvY0nUiiaSr8AAAA" +
  207.                                    "AElFTkSuQmCC",
  208.                                    "", "Bing - BT", "GET",
  209.                                    "http://www.bing.com/search?q={searchTerms}&form=BRTTDF");
  210.  
  211.     var newEngine = searchSvc.getEngineByName("Bing");
  212.  
  213.     if (replace && oldPosition) {
  214.       searchSvc.moveEngine(newEngine, oldPosition);
  215.     }
  216.     return newEngine;
  217.   }
  218.  
  219.   /* This functions updates the BT Search Engines with the current boom info */
  220.   function updateSearchEngine(brandObject) {
  221.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  222.                               .getService(Components.interfaces.nsIBrowserSearchService);
  223.  
  224.     var currentEngine = searchSvc.currentEngine;
  225.     var visibleEngines = searchSvc.getVisibleEngines({});
  226.     var askPosition;
  227.     var yahooPosition;
  228.     if (brandObject.askOriginCode) {
  229.       var askEngine = searchSvc.getEngineByName("Ask");
  230.       /* If there is a BT Ask, replace it */
  231.       if (askEngine && askEngine.description == "Ask - BT") {
  232.         var submission = askEngine.getSubmission("test", null);
  233.         if (!submission.uri.path.match(brandObject.askOriginCode)) {
  234.           for (let i=0; i < visibleEngines.length; i++) {
  235.             if (visibleEngines[i].description == "Ask - BT") {
  236.               askPosition = i;
  237.             }
  238.           }
  239.           searchSvc.removeEngine(askEngine);
  240.           var newAskEngine = addAsk(brandObject);
  241.           if (currentEngine == askEngine) {
  242.             searchSvc.currentEngine = newAskEngine;
  243.           }
  244.           searchSvc.moveEngine(newAskEngine, askPosition);
  245.         }
  246.       }
  247.     }
  248.     var yahooEngine = searchSvc.getEngineByName("Yahoo!");
  249.     /* If there is a BT Ask, replace it */
  250.     if (yahooEngine && yahooEngine.description == "Yahoo! - BT") {
  251.       var submission = yahooEngine.getSubmission("test", null);
  252.       if (!submission.uri.path.match(brandObject.releaseIdentifier)) {
  253.         for (let i=0; i < visibleEngines.length; i++) {
  254.           if (visibleEngines[i].description == "Yahoo! - BT") {
  255.             yahooPosition = i;
  256.           }
  257.         }
  258.         searchSvc.removeEngine(yahooEngine);
  259.         var newYahooEngine = addYahoo(brandObject);
  260.         if (currentEngine == yahooEngine) {
  261.           searchSvc.currentEngine = newYahooEngine;
  262.         }
  263.         searchSvc.moveEngine(newYahooEngine, yahooPosition);
  264.       }
  265.     }
  266.     /* keyword.URL */
  267.     var keywordSearch = true;
  268.     try {
  269.       keywordSearch = btPrefBranch.getBoolPref("keywordSearch");
  270.     } catch (ex) {}
  271.  
  272.     if (keywordSearch) {
  273.       var currentEngineDescription = currentEngine.description;
  274.  
  275.       if ((currentEngineDescription != "Ask - BT") &&
  276.           (currentEngineDescription != "Bing - BT") &&
  277.           (currentEngineDescription != "Yahoo! - BT")) {
  278.         currentEngineDescription = brandObject.defaultSearchEngine;
  279.       }
  280.  
  281.       switch (currentEngineDescription) {
  282.         case "Ask - BT":
  283.           prefbranch.setCharPref("keyword.URL", "http://www.ask.com/web?o=" + brandObject.askOriginCode + "&l=dis&q=");
  284.           break;
  285.         case "Yahoo! - BT":
  286.           prefbranch.setCharPref("keyword.URL", "http://search.yahoo.com/search?ei=UTF-8&fr=chrff-brandt_off&type=" + brandObject.releaseIdentifier + "&p=");
  287.           break;
  288.         case "Bing - BT":
  289.           prefbranch.setCharPref("keyword.URL", "http://www.bing.com/search?form=BRTTDF&q=");
  290.           break;
  291.       }
  292.     }
  293.   }
  294.  
  295.   function isDefaultSearchEngineBT(brandObject) {
  296.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  297.                               .getService(Components.interfaces.nsIBrowserSearchService);
  298.     var currentEngine = searchSvc.currentEngine;
  299.     if (currentEngine.description == brandObject.defaultSearchEngine) {
  300.       return true;
  301.     }
  302.     return false;
  303.   }
  304.  
  305.   /* optin indicates whether someone chose to do this or not */
  306.   function setDefaultSearchEngine(brandObject, optin) {
  307.     /* This assumes we've already added engines */
  308.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  309.                               .getService(Components.interfaces.nsIBrowserSearchService);
  310.  
  311.     var currentEngine = searchSvc.currentEngine.description;
  312.  
  313.     var newEngine;
  314.     switch (brandObject.defaultSearchEngine) {
  315.       case "Ask - BT":
  316.         /* Don't set default to someone else's Ask (Rare) */
  317.         var engine = searchSvc.getEngineByName("Ask");
  318.         if (engine.description == "Ask - BT") {
  319.           newEngine = engine;
  320.         }
  321.         prefbranch.setCharPref("keyword.URL", "http://www.ask.com/web?o=" + brandObject.askOriginCode + "&l=dis&q=");
  322.         break;
  323.       case "Bing - BT":
  324.         /* Don't set default to someone else's Bing (Rare) */
  325.         var engine = searchSvc.getEngineByName("Bing");
  326.         if (engine.description == "Bing - BT") {
  327.           newEngine = engine;
  328.         }
  329.         prefbranch.setCharPref("keyword.URL", "http://www.bing.com/search?form=BRTTDF&q=");
  330.         break;
  331.       case "Yahoo! - BT":
  332.         newEngine = searchSvc.getEngineByName("Yahoo!");
  333.         prefbranch.setCharPref("keyword.URL", "http://search.yahoo.com/search?ei=UTF-8&fr=chrff-brandt_off&type=" + brandObject.releaseIdentifier + "&p=");
  334.         break;
  335.     }
  336.     if (optin && !newEngine) {
  337.       /* We got here because there was optin, but we didn't add an engine because */
  338.       /* we couldn't step into a revenue connection. Because they opted in, we can */
  339.       switch (brandObject.defaultSearchEngine) {
  340.         case "Ask - BT":
  341.           newEngine = addAsk(brandObject, true);
  342.           break;
  343.         case "Yahoo! - BT":
  344.           newEngine = addYahoo(brandObject, true);
  345.           break;
  346.         case "Bing - BT":
  347.           newEngine = addBing(brandObject, true);
  348.           break;
  349.       }
  350.     }
  351.     if (newEngine) {
  352.       searchSvc.currentEngine = newEngine;
  353.     }
  354.  
  355.     btPrefBranch.setBoolPref("keywordSearch", true);
  356.     btPrefBranch.setBoolPref("tabSearch", true);
  357.   }
  358.  
  359.   function addSearchEngine(brandObject) {
  360.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  361.                               .getService(Components.interfaces.nsIBrowserSearchService);
  362.     var selectedEngine;
  363.     try {
  364.       selectedEngineName = prefbranch.getCharPref("browser.search.selectedEngine");
  365.     } catch (ex) {
  366.       selectedEngineName = searchSvc.currentEngine.name;
  367.     }
  368.     selectedEngine = searchSvc.getEngineByName(selectedEngineName);
  369.  
  370.     var addedAsk = false;
  371.  
  372.     if (brandObject.askOriginCode) {
  373.       var askPosition;
  374.       /* If they don't have an Ask, add it */
  375.       var askEngine = searchSvc.getEngineByName("Ask");
  376.       /* We only add our Ask if there is no other Ask */
  377.       if (!askEngine) {
  378.         addAsk(brandObject);
  379.         addedAsk = true;
  380.       }
  381.     }
  382.  
  383.     var addedBing = !!addBing(brandObject, true);
  384.     
  385.  
  386.     /* Bail if the selected engine is Yahoo or if it is an AMO build */
  387.     /* We don't bail for Yahoo! because that's ours, and we're going to replace it */
  388.     /* The preference won't be set if the user has never changed the search engine */
  389.     if (AMO || (selectedEngineName == "Yahoo")) {
  390.       return;
  391.     }
  392.  
  393.     var yahooPosition;
  394.  
  395.     /* If there is a Yahoo, replace it with our Yahoo! */
  396.     var oldYahooEngine = searchSvc.getEngineByName("Yahoo");
  397.     if (oldYahooEngine) {
  398.       var visibleEngines = searchSvc.getVisibleEngines({});
  399.       for (let i=0; i < visibleEngines.length; i++) {
  400.         if (visibleEngines[i].description == "Yahoo - BT") {
  401.           yahooPosition = i;
  402.         }
  403.       }
  404.       searchSvc.removeEngine(oldYahooEngine);
  405.     }
  406.  
  407.     var addedYahoo = false;
  408.  
  409.     /* Only add our search engine if there isn't one */
  410.     var yahooEngine = searchSvc.getEngineByName("Yahoo!");
  411.     if (!yahooEngine) {
  412.       addYahoo(brandObject);
  413.       addedYahoo = true;
  414.     }
  415.  
  416.     var newYahooEngine;
  417.     var newAskEngine;
  418.     var newBingEngine;
  419.     if (addedYahoo) {
  420.       newYahooEngine = searchSvc.getEngineByName("Yahoo!");
  421.     }
  422.     if (addedAsk) {
  423.       newAskEngine = searchSvc.getEngineByName("Ask");
  424.     }
  425.     if (addedBing) {
  426.       newBingEngine = searchSvc.getEngineByName("Bing");
  427.     }
  428.  
  429.     /* Put our Yahoo! at the sample place as the old Yahoo */
  430.     if (yahooPosition) {
  431.       searchSvc.moveEngine(newYahooEngine, yahooPosition);
  432.     }
  433.  
  434.     switch (brandObject.defaultSearchEngine) {
  435.       case "Ask - BT":
  436.         if (newBingEngine) {
  437.           searchSvc.moveEngine(newBingEngine, 0);
  438.         }
  439.         if (newYahooEngine) {
  440.           searchSvc.moveEngine(newYahooEngine, 0);
  441.         }
  442.         if (newAskEngine) {
  443.           searchSvc.moveEngine(newAskEngine, 0);
  444.         }
  445.         break;
  446.       case "Yahoo! - BT":
  447.         if (newBingEngine) {
  448.           searchSvc.moveEngine(newBingEngine, 0);
  449.         }
  450.         if (newAskEngine) {
  451.           searchSvc.moveEngine(newAskEngine, 0);
  452.         }
  453.         if (newYahooEngine) {
  454.           searchSvc.moveEngine(newYahooEngine, 0);
  455.         }
  456.         break;
  457.       case "Bing - BT":
  458.         if (newYahooEngine) {
  459.           searchSvc.moveEngine(newYahooEngine, 0);
  460.         }
  461.         if (newAskEngine) {
  462.           searchSvc.moveEngine(newAskEngine, 0);
  463.         }
  464.         if (newBingEngine) {
  465.           searchSvc.moveEngine(newBingEngine, 0);
  466.         }
  467.         break;
  468.     }
  469.   }
  470.  
  471.   function addBookmark(title, url, container) {
  472.     if (!container) {
  473.       container = bookmarks.bookmarksMenuFolder;
  474.     }
  475.     var bookmarks = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
  476.                               .getService(Components.interfaces.nsINavBookmarksService);
  477.     var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  478.                                 .getService(Components.interfaces.nsIIOService);
  479.     var uri = ioService.newURI(url, null, null);
  480.     bookmarks.insertBookmark(container, uri, -1, title);
  481.   }
  482.  
  483.   function toggleTheme(brandObject) {
  484.     var dynamicBoom = false;
  485.     try {
  486.       dynamicBoom = btPrefBranch.getBoolPref("dynamicBoom");
  487.     } catch (ex) {}
  488.  
  489.  
  490.     if (!dynamicBoom && (prefbranch.getCharPref("general.skins.selectedSkin") != "classic/1.0")) {
  491.       return;      
  492.     }
  493.  
  494.  
  495.     var currentBoom = btPrefBranch.getCharPref("currentBoom");
  496.     var bigBoom = true;
  497.     try {
  498.       bigBoom = btPrefBranch.getBoolPref("bigBoom");
  499.     } catch (ex) {
  500.     }    
  501.     if (bigBoom) {
  502.       var boomClient;
  503.       for (let i in BrandThunder.clients) {
  504.         for (let j in BrandThunder.clients[i].booms) {
  505.           if (j == currentBoom) {
  506.             boomClient = i;
  507.             break;
  508.           }
  509.         }
  510.       }
  511.       if (brandObject && (boomClient != brandObject.shortName)) {
  512.         return;
  513.       }
  514.       if (brandObject.utilities.LightweightThemeManager) {
  515.         brandObject.utilities.LightweightThemeManager.currentTheme = null;
  516.       }
  517.       document.getElementById("main-window").setAttribute("btBoom", currentBoom);
  518.       document.getElementById("main-window").setAttribute("bt-theme", currentBoom);
  519.       document.getElementById("main-window").setAttribute("btClient", boomClient);
  520.       /* If we have a home page, set it, otherwise remove attribute if it is there */
  521.       if (brandObject.homePage) {
  522.         var homePage;
  523.         if (typeof(brandObject.homePage) == "object") {
  524.           homePage = brandObject.homePage[currentBoom];
  525.         } else {
  526.           homePage = brandObject.homePage;
  527.         }
  528.         document.getElementById("main-window").setAttribute("btURLLeft", homePage);
  529.       } else {
  530.         document.getElementById("main-window").removeAttribute("btURLLeft");
  531.       }
  532.     } else {
  533.       document.getElementById("main-window").removeAttribute("btBoom");
  534.       document.getElementById("main-window").removeAttribute("bt-theme");
  535.       document.getElementById("main-window").removeAttribute("btClient");
  536.       /* Remove URLs from main window when we are switched to small boom */
  537.       document.getElementById("main-window").removeAttribute("btURLLeft");
  538.       document.getElementById("main-window").removeAttribute("btURLRight");
  539.     }
  540.   }
  541.   function switchBoom(brandObject, boomSwitch) {
  542.     /* Get the current boom */
  543.     var currentBoom = btPrefBranch.getCharPref("currentBoom");
  544.  
  545.     /* Find the client that corresponds to the current boom */
  546.     var boomClient;
  547.     for (let i in BrandThunder.clients) {
  548.       for (let j in BrandThunder.clients[i].booms) {
  549.         if (j == currentBoom) {
  550.           boomClient = i;
  551.           break;
  552.         }
  553.       }
  554.     }
  555.     /* If we didn't find a boomClient, must be invalid currentBoom */
  556.     /* Set currentBoom and return. We'll come back through this code again */
  557.     if (!boomClient) {
  558.       for (let i in brandObject.booms) {
  559.         btPrefBranch.setCharPref("currentBoom", i);
  560.         return; 
  561.       }
  562.     } else {
  563.       if (boomClient != brandObject.shortName) {
  564.         if (brandObject.homePage) {
  565.           var homePage;
  566.           if (typeof(brandObject.homePage) == "object") {
  567.             homePage = brandObject.homePage[currentBoom];
  568.           } else {
  569.             homePage = brandObject.homePage;
  570.           }
  571.  
  572.           /* If our homepage is set on main window, remove it */
  573.           var mainWindow = document.getElementById("main-window");
  574.           if (mainWindow.hasAttribute("btURLLeft") &&
  575.               mainWindow.getAttribute("btURLLeft") == homePage) {
  576.             mainWindow.removeAttribute("btURLLeft");
  577.           }
  578.         }
  579.         return;
  580.       }
  581.     }
  582.     /* If boomSwitch is set, this came as the result of the pref change */
  583.     /* Set the pref and let the big boom come through toggleTheme as a */
  584.     /* result of the pref change. Otherwise, call toggleTheme directly */
  585.     var bigBoom= true;
  586.     try {
  587.       bigBoom = btPrefBranch.getBoolPref("bigBoom");
  588.     } catch (ex) {
  589.     }
  590.     if (!bigBoom && boomSwitch) {
  591.       btPrefBranch.setBoolPref("bigBoom", true);
  592.     } else {
  593.       toggleTheme(brandObject);
  594.     }
  595.  
  596.     /* Figure out which toolbar applies to the current boom */
  597.     /* Note this can be either a boom specific toolbar or a client specific toolbar */
  598.     var toolbarRDF;
  599.     var boomToolbar;
  600.     var toolbar = document.getElementById("bt-" + currentBoom + "-toolbar");
  601.     if (toolbar) {
  602.       boomToolbar = currentBoom;
  603.       toolbarRDF = "chrome://browser/content/browser.xul#bt-" + currentBoom + "-toolbar";
  604.     } else {
  605.       /* Might be a client toolbar */
  606.       toolbar = document.getElementById("bt-" + boomClient + "-toolbar");
  607.       if (toolbar) {
  608.         boomToolbar = boomClient;
  609.         toolbarRDF = "chrome://browser/content/browser.xul#bt-" + boomClient + "-toolbar";
  610.       }
  611.     }
  612.     /* If we have a toolbar, show it */
  613.     if (toolbar) {
  614.       /* Honor user's collapsed settings */
  615.       try {
  616.         var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  617.         var dataSource = rdf.GetDataSource("rdf:local-store");
  618.         var collapsedResource = rdf.GetResource("collapsed");
  619.         toolbarRDF = rdf.GetResource(toolbarRDF);
  620.         var target = dataSource.GetTarget(toolbarRDF, collapsedResource, true);
  621.         if (target instanceof Components.interfaces.nsIRDFLiteral) {
  622.           toolbar.collapsed = target.Value;
  623.         } else {
  624.           toolbar.collapsed = false;
  625.         }
  626.       } catch(ex) {
  627.         toolbar.collapsed = false;
  628.       }
  629.       toolbar.setAttribute("toolbarname", toolbar.getAttribute("bt-toolbarname"));
  630.       var navbar = document.getElementById("nav-bar");
  631. //      if (navbar.nextSibling.id != "bt-" + currToolbar + "-toolbar") {
  632.       if (navbar.nextSibling != toolbar) {
  633.         navbar.parentNode.insertBefore(toolbar, navbar.nextSibling)
  634.       }
  635.     }
  636.  
  637.     /* Figure out which sidebar applies to the current boom */
  638.     /* Note this can be either a boom specific sidebar or a client specific sidebar */
  639.     var boomSidebar;
  640.     var sidebarmenu = document.getElementById("bt-" + currentBoom + "-sidebar-menu");
  641.     if (sidebarmenu) {
  642.       boomSidebar = currentBoom;
  643.     } else {
  644.       /* Might be a client toolbar */
  645.       sidebarmenu = document.getElementById("bt-" + boomClient + "-sidebar-menu");
  646.       if (sidebarmenu) {
  647.         boomSidebar = boomClient;
  648.       }
  649.     }
  650.  
  651.     /* Disable everything that doesn't correspond to the current toolbar */
  652.     /* Hide other sidebars */
  653.     for (let i in BrandThunder.clients) {
  654.       for (let j in BrandThunder.clients[i].booms) {
  655.         if (j != boomToolbar) {
  656.           try{
  657.             document.getElementById("bt-" + j + "-toolbar").collapsed = true;
  658.             document.getElementById("bt-" + j + "-toolbar").removeAttribute("toolbarname");
  659.           } catch (ex) {}
  660.         }
  661.         if (j != boomSidebar) {
  662.           try{
  663.             document.getElementById("bt-" + j + "-sidebar-menu").hidden = true;
  664.           } catch (ex) {}
  665.         }
  666.       }
  667.       if (i != boomClient) {
  668.           try{
  669.             document.getElementById("bt-" + i + "-toolbar").collapsed = true;
  670.             document.getElementById("bt-" + i + "-toolbar").removeAttribute("toolbarname");
  671.           } catch (ex) {}        
  672.           try{
  673.             document.getElementById("bt-" + i + "-sidebar-menu").hidden = true;
  674.           } catch (ex) {}        
  675.       }
  676.     }
  677.  
  678.     if (sidebarmenu) {
  679.       sidebarmenu.hidden = false;
  680.     }
  681.     if (!document.getElementById("sidebar-box").hidden) {
  682.       if (document.getElementById("sidebar-box").getAttribute("src").match("btSidebar.xul")) {
  683.         if (boomSidebar) {
  684.           toggleSidebar();
  685.           toggleSidebar("bt-" + boomSidebar + "-sidebar", true);
  686.         } else {
  687.           toggleSidebar();
  688.         }
  689.       }
  690.     }
  691.  
  692.   
  693.     /* Update the search engine to correspond to the current boomClient */
  694.     updateSearchEngine(BrandThunder.clients[boomClient]);
  695.     var updateUserAgent = true;
  696.     try {
  697.       updateUserAgent = btPrefBranch.getBoolPref("updateUserAgent");
  698.     } catch (ex) {}
  699.     if (updateUserAgent) {
  700.       prefbranch.setCharPref("general.useragent.extra.brandthunder", "(BT-" + boomClient + ")");
  701.     }
  702.   }
  703.  
  704.   function uninstall (brandObject, btClientBundle) {
  705.     function postUninstall(brandObject, btClientBundle) {
  706.       brandObject.utilities.openLink(brandObject, null, "http://brandthunder.com/uninstall.php?&type=" + brandObject.releaseIdentifier);
  707.       
  708.       var button = promptService.confirmEx(window, btClientBundle.getString("clientName"), btClientBundle.getString("restart.confirm"),
  709.                                            (promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
  710.                                            (promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
  711.                                            null, null, null, null, {});
  712.       if (button == 0) {
  713.         brandObject.utilities.restartApp();
  714.       }
  715.     }
  716.     var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  717.                                     .getService(Components.interfaces.nsIPromptService);
  718.     var em = Components.classes["@mozilla.org/extensions/manager;1"]
  719.                          .getService(Components.interfaces.nsIExtensionManager);
  720.     var name = em.getInstallLocation(brandObject.extensionID).name;
  721.     if (name == "winreg-app-global") {
  722.       const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
  723.       var key = Components.classes["@mozilla.org/windows-registry-key;1"]
  724.                           .createInstance(nsIWindowsRegKey);
  725.       var rootKey = nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE;
  726.       key.create(rootKey, "SOFTWARE\\Mozilla\\Firefox\\Extensions", nsIWindowsRegKey.ACCESS_READ);
  727.       var path = key.readStringValue(brandObject.extensionID);
  728.       var file = Components.classes["@mozilla.org/file/local;1"]
  729.                            .createInstance(Components.interfaces.nsILocalFile);
  730.       file.initWithPath(path + "\\" + "unins000.exe");
  731.       
  732.       var process = Components.classes["@mozilla.org/process/util;1"]
  733.                               .createInstance(Components.interfaces.nsIProcess);
  734.       process.init(file);
  735.       
  736.       var args = [];
  737.       process.run(false, args, args.length);
  738.       function checkUninstallStatus(process, brandObject, btClientBundle) {
  739.         switch (process.exitValue) {
  740.           case -1:
  741.             window.setTimeout(checkUninstallStatus, 1000, process, brandObject, btClientBundle);
  742.             break;
  743.           case 1:
  744.             return;
  745.           case 0:
  746.             window.setTimeout(postUninstall, 2500, brandObject, btClientBundle);
  747.             key.removeValue(brandObject.extensionID);
  748.             break;
  749.         }
  750.       }
  751.       window.setTimeout(checkUninstallStatus, 1000, process, brandObject, btClientBundle);
  752.     } else {
  753.       var button = promptService.confirmEx(window, btClientBundle.getString("clientName"), btClientBundle.getString("uninstall.confirm"),
  754.                                            (promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
  755.                                            (promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
  756.                                            null, null, null, null, {});
  757.       if (button == 0) {
  758.         var observerService = Components.classes["@mozilla.org/observer-service;1"]
  759.                                         .getService(Components.interfaces.nsIObserverService);
  760.         var em = Components.classes["@mozilla.org/extensions/manager;1"]
  761.                            .getService(Components.interfaces.nsIExtensionManager);
  762.         var name = em.getInstallLocation(brandObject.extensionID).name;
  763.         try {
  764.           em.uninstallItem(brandObject.extensionID);
  765.           observerService.notifyObservers(em.getItemForID(brandObject.extensionID),
  766.                                         "em-action-requested", "item-uninstalled");
  767.         } catch(ex) {}
  768.         postUninstall(brandObject, btClientBundle);
  769.       }
  770.     }
  771.   }
  772.  
  773.   function firstRun(brandObject, btClientBundle) {
  774.     var firstrun = true;
  775.     
  776.     var btClientPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  777.                                  .getService(Components.interfaces.nsIPrefService)
  778.                                  .getBranch("extensions.brandthunder." + brandObject.clientCode + ".");
  779.  
  780.     var validBoom = false;
  781.     try {
  782.       var currentBoom = btPrefBranch.getCharPref("currentBoom");
  783.       for (let i in BrandThunder.clients) {
  784.         for (let j in BrandThunder.clients[i].booms) {
  785.           if (j == currentBoom) {
  786.             validBoom = true;
  787.           }
  788.         }
  789.       }
  790.     } catch (ex) {}
  791.  
  792.     if (!validBoom) {
  793.       /* currentBoom is not valid */
  794.       for (let i in brandObject.booms) {
  795.         btPrefBranch.setCharPref("currentBoom", i);
  796.         break;
  797.       }
  798.     }
  799.  
  800.     if (!btClientBundle) {
  801.       btClientBundle = document.getElementById("btClientBundle_" + brandObject.shortName);
  802.     }
  803.     /* If for some reason we didn't get a client bundle, try a boom bundle */
  804.     if (!btClientBundle) {
  805.       btClientBundle = document.getElementById("btBoomBundle_" + currentBoom);
  806.     }
  807.  
  808.     function removeXPIs(brandObject) {
  809.       try {
  810.         var extdir = em.getInstallLocation(brandObject.extensionID)
  811.                          .getItemLocation(brandObject.extensionID);
  812.       } catch (ex) {
  813.         return;
  814.       }
  815.     
  816.       var e = extdir.directoryEntries;
  817.       while (e.hasMoreElements()) {
  818.         var f = e.getNext().QueryInterface(Components.interfaces.nsIFile);
  819.         var splitpath = f.path.split(".");
  820.         /* Only load XPI files */
  821.         if (splitpath[splitpath.length-1] == "xpi") {
  822.           try {
  823.             f.remove(true);
  824.           } catch (ex) {}
  825.         }
  826.       }
  827.     }
  828.  
  829.     function surfCanyonUpgrade(brandObject, btClientBundle){
  830.       var upgradeMessage = btClientBundle.getString("upgradeMessage");
  831.       var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  832.                                     .getService(Components.interfaces.nsIPromptService);
  833.       var state = {};
  834.       state.value = true;
  835.       promptService.confirmEx(window, btClientBundle.getString("clientName"),
  836.                               upgradeMessage,
  837.                               promptService.BUTTON_TITLE_OK,                                       
  838.                               null,null,null,"Install Surf Canyon on the next restart",state);
  839.       if (state.value == false) {
  840.         removeXPIs(brandObject);
  841.       }
  842.     }
  843.  
  844.     try {
  845.       firstrun = btClientPrefBranch.getBoolPref("firstrun");
  846.       if (firstrun == false) {
  847.         /* Check if we are an upgrade */
  848.         var upgrade = false;
  849.         try {
  850.           upgrade = btClientPrefBranch.getBoolPref("upgrade");
  851.           if (upgrade) {
  852.             try {
  853.               var upgradeMessage = btClientBundle.getString("upgradeMessage");
  854.               /* check if surf canyon is already installed */
  855.               var em = Components.classes["@mozilla.org/extensions/manager;1"]
  856.                                  .getService(Components.interfaces.nsIExtensionManager);
  857.  
  858.               var scinstalled = em.getInstallLocation("{75623d5d-4683-402a-b610-ac4bab767c86}")
  859.               if (!scinstalled) {
  860.                 window.setTimeout(surfCanyonUpgrade, 1500, brandObject, btClientBundle);
  861.               } else {
  862.                 removeXPIs(brandObject);
  863.               }
  864.             } catch (ex) {
  865.               /* No upgradeMessage specified, so don't display message */
  866.             }
  867.             btClientPrefBranch.clearUserPref("upgrade");          
  868.           }
  869.         } catch (ex) {}
  870.         return;
  871.       }
  872.     } catch(e) {
  873.       //nothing
  874.     }
  875.   
  876.     btClientPrefBranch.setBoolPref("firstrun",false);
  877.  
  878.     function firstRunNotifications(brandObject) {
  879.       function askAboutHomepage(event) {
  880.         /* Only ask about home page if the notification happens on one of our pages */
  881.         if (brandObject.welcomePage) {
  882.           if (!(content.document.location.href.match(brandObject.welcomePage))) {
  883.             return;
  884.           }
  885.         } else if (brandObject.startPage) {
  886.           if (content.document.location.href != brandObject.startPage) {
  887.             return;
  888.           }
  889.         } else {
  890.           event.target.removeEventListener("load", askAboutHomepage, false);
  891.           return; 
  892.         }
  893.         event.target.removeEventListener("load", askAboutHomepage, false);
  894.         function yes() {
  895.           var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
  896.                          .getService(Components.interfaces.nsIPrefBranch);
  897.           var homePage;
  898.           if (typeof(brandObject.homePage) == "object") {
  899.             homePage = brandObject.homePage[currentBoom];
  900.           } else {
  901.             homePage = brandObject.homePage;
  902.           }
  903.           prefbranch.setCharPref("browser.startup.homepage", homePage);
  904.         }
  905.         var nbox_buttons = [
  906.           {
  907.             label: "Yes",
  908.             accessKey: "Y",
  909.             callback: yes,
  910.             popup: null
  911.           },
  912.           {
  913.             label: "No",
  914.             accessKey: "N",
  915.             callback: function() {},
  916.             popup: null 
  917.           }
  918.         ]
  919.         var nbox = gBrowser.getNotificationBox();
  920.         if (brandObject.homePage) {
  921.           try {
  922.             var homepageQuestion = btClientBundle.getString("homepageQuestion");
  923.             nbox.appendNotification(homepageQuestion, "brandthunder",
  924.                                     "chrome://" + brandObject.packageName + "/skin/favicon.png",
  925.                                     nbox.PRIORITY_INFO_HIGH, nbox_buttons);
  926.           } catch (ex) {}
  927.         }
  928.         if (content.document.location.href.match("overlay")) {
  929.           if (!brandObject.utilities.isDefaultSearchEngineBT(brandObject)) {
  930.             var search = content.document.getElementById("search");
  931.             if (search) {
  932.               search.style.display = "block";
  933.             } else {
  934.               /* If we don't have a search block, even if we're AMO, do the switch */
  935.               brandObject.utilities.setDefaultSearchEngine(brandObject, true);
  936.             }
  937.           }
  938.         }
  939.       }
  940.       /* If we have a start page, add it */
  941.       if (brandObject.startPage) {
  942.         gBrowser.selectedTab = gBrowser.addTab(brandObject.startPage);
  943.       }
  944.       /* If we have a welcome page, add it */
  945.       if (brandObject.welcomePage) {
  946.         var welcomePage = brandObject.welcomePage;
  947.         if (brandObject.firstrun || (!brandObject.utilities.isDefaultSearchEngineBT(brandObject) && AMO)) {
  948.           welcomePage += "?overlay";
  949.         }
  950.         gBrowser.selectedTab = gBrowser.addTab(welcomePage);
  951.       }
  952.       gBrowser.selectedTab.addEventListener("load", askAboutHomepage, false);
  953.       if (brandObject.firstRunSidebar) {
  954.         toggleSidebar(brandObject.firstRunSidebar, true);
  955.       }
  956.     }
  957.     /* Delay startup notifications for a 1.5 seconds */
  958.     window.setTimeout(firstRunNotifications, 1500, brandObject);
  959.     /* Add domains to permission manager for installing and popups */
  960.     if (brandObject.domains) {
  961.       for (let i=0; i < brandObject.domains.length; i++) {
  962.         brandObject.utilities.addToPermissionManager(brandObject.domains[i]);
  963.       }
  964.     }
  965.     if (brandObject.bookmarks) {
  966.       for (let i in brandObject.bookmarks) {
  967.         if (typeof(brandObject.bookmarks[i]) == "object") {
  968.           var bookmarks = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
  969.                                     .getService(Components.interfaces.nsINavBookmarksService);
  970.  
  971.           var folder =  bookmarks.createFolder(bookmarks.bookmarksMenuFolder, i, -1);
  972.  
  973.           for (let j in brandObject.bookmarks[i]) {
  974.             brandObject.utilities.addBookmark(j, brandObject.bookmarks[i][j], folder);
  975.           }
  976.          } else {
  977.           brandObject.utilities.addBookmark(i, brandObject.bookmarks[i]);
  978.         }
  979.       }
  980.     }
  981.     
  982.     brandObject.utilities.addSearchEngine(brandObject);
  983.     if (!AMO) {
  984.       brandObject.utilities.setDefaultSearchEngine(brandObject);
  985.     }
  986.   }
  987.  
  988.   brandObject.utilities.isFullBuild = isFullBuild;
  989.   brandObject.utilities.openLink = openLink;
  990.   brandObject.utilities.restartApp = restartApp;
  991.   brandObject.utilities.addToPermissionManager = addToPermissionManager;
  992.   brandObject.utilities.addSearchEngine = addSearchEngine;
  993.   brandObject.utilities.setDefaultSearchEngine = setDefaultSearchEngine;
  994.   brandObject.utilities.isDefaultSearchEngineBT = isDefaultSearchEngineBT;
  995.   brandObject.utilities.addBookmark = addBookmark;
  996.   brandObject.utilities.uninstall = uninstall;
  997.   brandObject.utilities.firstRun = firstRun;
  998.   brandObject.utilities.switchBoom = switchBoom;
  999.   brandObject.utilities.toggleTheme = toggleTheme;
  1000.   try {
  1001.     Components.utils.import("resource://gre/modules/JSON.jsm", brandObject.utilities);
  1002.     brandObject.utilities.JSON.stringify = brandObject.utilities.JSON.toString;
  1003.     brandObject.utilities.JSON.parse = brandObject.utilities.JSON.fromString;
  1004.   } catch (ex) {
  1005.     /* Firefox 3.1 has native JSON support */
  1006.     brandObject.utilities.JSON = JSON;
  1007.   }
  1008.  
  1009.   try {
  1010.     Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", brandObject.utilities);
  1011.   } catch (ex) {
  1012.   }
  1013.  
  1014.   brandObject.releaseIdentifier = getReleaseIdentifier(brandObject);
  1015.  
  1016.   if (brandObject.releaseIdentifier.indexOf("A") != -1) {
  1017.     AMO = true;
  1018.   }
  1019.   
  1020.   /* Needed for compatibility with old booms */
  1021.   brandObject.utilities.getReleaseIdentifier = getReleaseIdentifier;
  1022.  
  1023.   /* So other clients won't call our BrandThunder.initialize */
  1024.   delete BrandThunder.initialize;
  1025. }
  1026.